<template include="./view/htm/my_shop.template.htm">
	<slot name="my_body">
		<div class="col-lg-6 mx-auto">
			<form action="<?php echo url('my-shop-admin');?>" method="post" id="form">
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">选择店铺</label>
					<select class="custom-select" name="admin_shop" id="admin_shop">
						<?php foreach ($shoplist as $sid => $_shop){ ?>
							<option value="<?php echo $_shop['sid'] ?>"><?php echo $_shop['name'] ?></option>
						<?php } ?>
					</select>	
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">店铺名称</label>
					<input type="text" class="form-control" id="name" name="name" placeholder="店铺名称" required=""/>
					<div class="invalid-feedback"></div>
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">LOGO</label>
					<div class="custom-file mt-1">
						<input type="file" class="custom-file-input" name="logo" data-assoc="logo_img" id="logo">
						<label class="custom-file-label" for="logo">选择Logo</label>
						
					</div>
					<img src="" id="logo_img" class="avatar-5">
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">店铺介绍</label>
					<textarea class="form-control" placeholder="" name="intro" id="intro" style="height: 300px;display:none;"></textarea>

					<div id="editor_intro" class="">
					</div>
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">服务范围</label>
					<textarea class="form-control" placeholder="" name="service" id="intro" style="height: 300px;display:none;"></textarea>

					<div id="editor_service" class="">
					</div>
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">热搜榜</label>
					<textarea class="form-control" placeholder="" name="hot" id="intro" style="height: 300px;display:none;"></textarea>

					<div id="editor_hot" class="">
					</div>
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">联系方式</label>
					<textarea class="form-control" placeholder="" name="contact" id="intro" style="height: 300px;display:none;"></textarea>

					<div id="editor_contact" class="">
					</div>
				</div>
				<div class="form-group row">
					<label for="admin_shop" class="col-form-label">幻灯片</label>
					<div class="custom-file mt-1">
						<input type="file" class="custom-file-input" name="slide_1" data-assoc="slide_1_img" id="slide_1">
						<label class="custom-file-label" for="slide_1">选择幻灯片一</label>
						
					</div>
					<img src="" id="slide_1_img" style="width: 100px;">
					<div class="custom-file mt-1">
						<input type="file" class="custom-file-input" name="slide_2" data-assoc="slide_2_img" id="slide_2">
						<label class="custom-file-label" for="slide_2">选择幻灯片二</label>
						
					</div>
					<img src="" id="slide_2_img" style="width: 100px;">
					<div class="custom-file mt-1">
						<input type="file" class="custom-file-input" name="slide_3" data-assoc="slide_3_img" id="slide_3">
						<label class="custom-file-label" for="slide_3">选择幻灯片三</label>
						

					</div>
					<img src="" id="slide_3_img" style="width: 100px;">
					<div class="custom-file mt-1">
						<input type="file" class="custom-file-input" name="slide_4" data-assoc="slide_4_img" id="slide_4">
						<label class="custom-file-label" for="slide_4">选择幻灯片四</label>
						
					</div>
					<img src="" id="slide_4_img" style="width: 100px;">
				</div>
				<div>
					<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>...">提交修改</button>
				</div>
			</form>
		</div>
	</slot>
</template>

<script>
$('a[data-active="my-shop-admin"]').addClass('active');
</script>
<script src="https://unpkg.com/wangeditor@3.1.1/release/wangEditor.min.js" type="text/javascript"></script>
<script type="text/javascript">
	var E = window.wangEditor
	var editor_intro = new E('#editor_intro')
	var $message_intro = $('#intro')

	editor_intro.customConfig.zIndex = 0
	//editor.customConfig.uploadImgShowBase64 = true
	//editor.customConfig.uploadImgServer = '<?php echo url('thread-upload') ?>'
	//editor.customConfig.uploadFileName = 'file'

	editor_intro.customConfig.menus = [
		'head',  // 标题
		'bold',  // 粗体
		'fontSize',  // 字号
		'italic',  // 斜体
		'underline',  // 下划线
		'strikeThrough',  // 删除线
		'foreColor',  // 文字颜色
		'backColor',  // 背景颜色
		'link',  // 插入链接
		'list',  // 列表
		'justify',  // 对齐方式
		'quote',  // 引用
		'image',  // 插入图片
		'table',  // 表格
		'undo',  // 撤销
	]
	editor_intro.create()
	editor_intro.txt.html($message_intro.val());
</script>
<script type="text/javascript">
	var E = window.wangEditor
	var editor_service = new E('#editor_service')
	var $message_service = $('#service')

	editor_service.customConfig.zIndex = 0
	//editor.customConfig.uploadImgShowBase64 = true
	//editor.customConfig.uploadImgServer = '<?php echo url('thread-upload') ?>'
	//editor.customConfig.uploadFileName = 'file'

	editor_service.customConfig.menus = [
		'head',  // 标题
		'bold',  // 粗体
		'fontSize',  // 字号
		'italic',  // 斜体
		'underline',  // 下划线
		'strikeThrough',  // 删除线
		'foreColor',  // 文字颜色
		'backColor',  // 背景颜色
		'link',  // 插入链接
		'list',  // 列表
		'justify',  // 对齐方式
		'quote',  // 引用
		'image',  // 插入图片
		'table',  // 表格
		'undo',  // 撤销
	]
	editor_service.create()
	editor_service.txt.html($message_service.val());
</script>
<script type="text/javascript">
	var E = window.wangEditor
	var editor_hot = new E('#editor_hot')
	var $message_hot = $('#hot')

	editor_hot.customConfig.zIndex = 0
	//editor.customConfig.uploadImgShowBase64 = true
	//editor.customConfig.uploadImgServer = '<?php echo url('thread-upload') ?>'
	//editor.customConfig.uploadFileName = 'file'

	editor_hot.customConfig.menus = [
		'head',  // 标题
		'bold',  // 粗体
		'fontSize',  // 字号
		'italic',  // 斜体
		'underline',  // 下划线
		'strikeThrough',  // 删除线
		'foreColor',  // 文字颜色
		'backColor',  // 背景颜色
		'link',  // 插入链接
		'list',  // 列表
		'justify',  // 对齐方式
		'quote',  // 引用
		'image',  // 插入图片
		'table',  // 表格
		'undo',  // 撤销
	]
	editor_hot.create()
	editor_hot.txt.html($message_hot.val());
</script>
<script type="text/javascript">
	var E = window.wangEditor
	var editor_contact = new E('#editor_contact')
	var $message_contact = $('#contact')

	editor_contact.customConfig.zIndex = 0
	//editor.customConfig.uploadImgShowBase64 = true
	//editor.customConfig.uploadImgServer = '<?php echo url('thread-upload') ?>'
	//editor.customConfig.uploadFileName = 'file'

	editor_contact.customConfig.menus = [
		'head',  // 标题
		'bold',  // 粗体
		'fontSize',  // 字号
		'italic',  // 斜体
		'underline',  // 下划线
		'strikeThrough',  // 删除线
		'foreColor',  // 文字颜色
		'backColor',  // 背景颜色
		'link',  // 插入链接
		'list',  // 列表
		'justify',  // 对齐方式
		'quote',  // 引用
		'image',  // 插入图片
		'table',  // 表格
		'undo',  // 撤销
	]
	editor_contact.create()
	editor_contact.txt.html($message_contact.val());
</script>
<script type="text/javascript">
	var shoplist = <?php echo json_encode($shoplist); ?>;
	var shopselect = $('#admin_shop');
	var shopname = $('#name')
	var shoplogo = $('#logo_img')

	var shop = shopselect.val();
	shopname.val(shoplist[shop]['name']);
	editor_intro.txt.html(shoplist[shop]['intro'])
	editor_service.txt.html(shoplist[shop]['service'])
	editor_hot.txt.html(shoplist[shop]['hot'])
	editor_contact.txt.html(shoplist[shop]['contact'])
	shoplogo.attr('src',shoplist[shop]['logo'])

	shopselect.on('change',function(){
		var shop = shopselect.val();
		shopname.val(shoplist[shop]['name']);
		editor_intro.txt.html(shoplist[shop]['intro'])
		editor_service.txt.html(shoplist[shop]['service'])
		editor_hot.txt.html(shoplist[shop]['hot'])
		editor_contact.txt.html(shoplist[shop]['contact'])
		shoplogo.attr('src',shoplist[shop]['logo'])
	});
</script>
<script>
var jform = $('#form');
var jsubmit = $('#submit');

jform.base64_encode_file();
jform.on('submit', function() {
	jform.reset();
	jsubmit.button('loading');
	
	var postdata = jform.serializeObject();

	postdata['intro'] = editor_intro.txt.html();
	postdata['service'] = editor_service.txt.html();
	postdata['hot'] = editor_hot.txt.html();
	postdata['contact'] = editor_contact.txt.html();

	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(3000).button('reset');
		} else if(xn.is_number(code)) {
			alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});
</script>